package cn.wolfcode.shop.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.wolfcode.shop.vo.JSONResult;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

	@ExceptionHandler(Exception.class)
	public JSONResult exceptionHangler(Exception e) {
		e.printStackTrace();
		JSONResult jsonResult = new JSONResult();
		if (e instanceof GlobalException) {
			GlobalException ge = (GlobalException) e;
			jsonResult.setExceptionMsg(ge.getCodeMsg());
		}else {
			jsonResult.setExceptionMsg(CodeMsg.SERVER_EXPTION);
		}
		return jsonResult;
	}
}
